package com.huifaapp.mall.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.huifaapp.mall.R;
import com.huifaapp.mall.activity.RankingRanNo1HtmlActivity;
import com.huifaapp.mall.bean.HotingBean;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 品牌列表适配器
 */
public class HomeLivingMoneyPopularActivitiesViewAdapter extends BaseAdapter{

	private Context context;
	private LayoutInflater inflater;
	private List<HotingBean.DataBean> list;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	private boolean isChenck=false;
	private ArrayList<String> ar=new ArrayList<String>();
	public HomeLivingMoneyPopularActivitiesViewAdapter(Context context, List<HotingBean.DataBean> list) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.list=list;
	}
	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public List<HotingBean.DataBean> getList() {
		return list;
	}

	public HomeLivingMoneyPopularActivitiesViewAdapter setList(List<HotingBean.DataBean> list) {
		this.list = list;
		return this;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;
		
		if (null == convertView) {
			convertView = inflater.inflate(R.layout.item_home_living_money_popularactivities_gridview, null);
			holder = new ViewHolder();
			holder.iv_item_home_living_money_popularActivities_image= (ImageView) convertView.findViewById(R.id.iv_item_home_living_money_popularActivities_image);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		final HotingBean.DataBean bean=list.get(position);
		uploadimageview(holder.iv_item_home_living_money_popularActivities_image,bean.getImg(),null,context);
		holder.iv_item_home_living_money_popularActivities_image.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (bean.getLinkType().equals("h5")){
					Intent intent=new Intent(context, RankingRanNo1HtmlActivity.class);
					intent.putExtra("url",bean.getValue());
					context.startActivity(intent);
				}
			}
		});
		return convertView;
	}
	
	
	
	class ViewHolder {
		private ImageView iv_item_home_living_money_popularActivities_image;
	}

	public static void uploadimageview(final ImageView views, String url, String bili, Context c) {
		DisplayImageOptions HXOptions = new DisplayImageOptions.Builder()
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.considerExifParams(true)
				.bitmapConfig(Bitmap.Config.RGB_565).build();
		ImageLoader.getInstance().displayImage(url, views, HXOptions);
	}
}
